/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newkfp;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author $alama
 */
@Stateless
public class BillFacade extends AbstractFacade<Bill> {
    @PersistenceContext(unitName = "KFPNEWPU")
    private EntityManager em;

    public EntityManager getEntityManager() {
        return em;
    }
//1030000023396566201205
    public BillFacade() {
        super(Bill.class);
    }

  public   Item getItemByName(String item) {
      
           Query query = getEntityManager().createNamedQuery("Item.findByItemName");
        query.setParameter("itemName", item);
              List list = query.getResultList();
               return (Item)list.get(0); 
     
        
        
    }
  
    public Item getItemByFactoryAndCountry(String subItemName,Factory factoryID) {
        Query query = getEntityManager().createNamedQuery("Item.findByItemNameAndFactoryIDAndCountryID");
        query.setParameter("itemName", subItemName);
        query.setParameter("factoryID", factoryID);
        Item item = (Item)query.getSingleResult();
        return item;
    }

  public   boolean checkDoc_bill_numbers(int docNumber, int billNumber) {
      boolean found=true;
      Query query = getEntityManager().createNamedQuery("Bill.checkBillNumber");
        query.setParameter("billNumber", billNumber);
        query.setParameter("docNum", docNumber);
        

        
        List<Bill> bill = query.getResultList();
       if( !bill.isEmpty())
       {
           System.out.println(" this Bill inserted Befor");
  
        found=false;   
       }
        return found;
    }
}
